// simple_Json project simple_Json.go
package simplejson

import "encoding/json"



type Json interface {
	Data() interface{}


	Set(key string, v interface{})

	Marshal() ([]byte, error)
	Bool() bool
	Interface()interface{}
	Int() int
	Uint() uint
	Int64() int64
	Uint64() uint64
	Float32() float32
	Float64() float64
	String() string
	Exist(key string) bool
	Get(key string) Json
	GetInterface(key string) interface{}
	GetBool(key string) bool
	GetInt(key string) int
	GetUint(key string) uint
	GetInt64(key string) int64
	GetUint64(key string) uint64
	GetFloat32(key string) float32
	GetFloat64(key string) float64
	GetString(key string) string

	Foreach(func(int,string, Json)bool)

	IsArray() bool
	ArrayLen() int
	Add(v interface{})
	NewObjectAdd() Json
	NewArrayAdd() Json
	GetByIndex(idx int) Json
	GetInterfaceByIndex(idx int) interface{}
	GetBoolByIndex(idx int) bool
	GetIntByIndex(idx int) int
	GetUintByIndex(idx int) uint
	GetInt64ByIndex(idx int) int64
	GetUint64ByIndex(idx int) uint64
	GetFloat32ByIndex(idx int) float32
	GetFloat64ByIndex(idx int) float64
	GetStringByIndex(idx int) string
}

func NewArray() Json {
	//return &_Json{data: make([]interface{}, 0)}
	return &_Json{data: newArrayJson()}
}
func New() Json {
	return &_Json{data: make(map[string]interface{})}
}
func NewJson(d []byte) (Json, error) {
	var data interface{}
	err := json.Unmarshal(d, &data)
	if err != nil {
		return nil, err
	}
	return &_Json{data: data}, nil
}

func Unmarshal(d []byte) Json {
	var data interface{}
	json.Unmarshal(d, &data)
	return &_Json{data: data}
}
